//
//  IntegralDetailViewController.m
//  Logistics
//
//  Created by luojinrong11 on 2018/4/20.
//  Copyright © 2018年 com.Logistics. All rights reserved.
//

#import "IntegralDetailViewController.h"
#import "IntegralDetailCell.h"
#import "IntegralUseModel.h"
#import "GRPersonAction.h"
@interface IntegralDetailViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    NSInteger pageIndex;
}

@property (strong, nonatomic) IBOutlet UITableView *detailList;
@property(nonatomic,strong)NSMutableArray * detailArr;

@end

@implementation IntegralDetailViewController
-(NSMutableArray *)detailArr {
    if (!_detailArr) {
        _detailArr = [NSMutableArray array];
    }
    return _detailArr;
}

-(void)getIntegralUseDetailList:(GRRefresh)freshType {
    [GRPersonAction getUserPointLogList:@{@"pageIndex":@(pageIndex)} CallBack:^(BOOL success, id responseObject, GRError *error) {
          if (success) {
            NSLog(@"积分明细%@",responseObject);
              if (freshType == GRRefreshForHeader) {
                  [self.detailArr removeAllObjects];
              }
              for (NSDictionary * useDic in responseObject) {
                  IntegralUseModel * useModel = [IntegralUseModel yy_modelWithDictionary:useDic];
                  [self.detailArr addObject:useModel];
              }
              [self.detailList.mj_header endRefreshing];
              [self.detailList.mj_footer endRefreshing];
            [self.detailList reloadData];
          }
    }];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.detailList.delegate = self;
    self.detailList.dataSource = self;
    self.navigationItem.title = @"使用明细";
    [self.detailList registerNib:[UINib nibWithNibName:@"IntegralDetailCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"detailCell"];
    self.detailList.tableFooterView = [[UIView alloc]init];
    WEAKSELF
    self.detailList.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        pageIndex = 1;
        [weakSelf getIntegralUseDetailList:GRRefreshForHeader];
    }];
    self.detailList.mj_footer = [GRRefreshBackFooter footerWithRefreshingBlock:^{
        pageIndex ++ ;
        [weakSelf getIntegralUseDetailList:GRRefreshForFooter];
    }];
    [self.detailList.mj_header beginRefreshing];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    IntegralDetailCell * cell = [tableView dequeueReusableCellWithIdentifier:@"detailCell" forIndexPath:indexPath];
    cell.useModel = self.detailArr[indexPath.row];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.detailArr.count;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
